<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['status']=$this->member_status;
$tabs=array(
	array('op'=>'list','title'=>'全部用户'),
	array('op'=>'edit','title'=>'编辑用户'),
); 
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=$_RQ['mid'];
		$return['params']['mid']=$_RQ['mid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_lvpai_member',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：</br>1、用户注册后，才可以查看内容！','del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员id','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'realname','title'=>'联系人','type'=>'string'),
			array('name'=>'mobile','title'=>'联系电话','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		)
	);
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_lvpai_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array('get_type'=>0);
	}
	$item['upass']='';
	$item['endtime']=date('Y-m-d H:i:s',$item['endtime']);
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回用户列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
						array(
							'title'=>'基本信息',
							'list'=>array(
								array('name'=>'realname','title'=>'联系人','type'=>'string'),
								array('name'=>'avatar','title'=>'头像','type'=>'image'),
								array('name'=>'mobile','title'=>'联系电话','type'=>'string'),
								array('name'=>'uname','must'=>true,'title'=>'账户名','type'=>'string'),
								array('name'=>'upass','title'=>'账户密码','type'=>'string'),
								array('name'=>'endtime','title'=>'到期时间','type'=>'time'),
								array('name'=>'qq','title'=>'QQ','type'=>'string'),
								array('name'=>'email','title'=>'邮箱','type'=>'string'),
								array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
								array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
							)
						),
			
			)
	);
	$return['sex']=array(1=>'男',2=>'女');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'realname'=>$postdata['realname'],
		'avatar'=>$postdata['avatar'],
		'mobile'=>$postdata['mobile'],
		'uname'=>$postdata['uname'],
		'qq'=>$postdata['qq'],
		'email'=>$postdata['email'],
		'sex'=>$postdata['sex'],
		'status'=>intval($postdata['status']),
		'upass'=>base64_encode($postdata['upass']),
		'endtime'=>strtotime($postdata['endtime']),
	);
	$id=intval($postdata['id']);
	if($id){
		if(!$postdata['upass']){
			unset($data['upass']);
		}
		pdo_update('jy_lvpai_member',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_lvpai_member',$data);
	}
	exi('操作成功！','','list');
}

if($_RQ['op']=='member'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	if($_RQ['mid']){
		$params=array('uniacid'=>$_SESSION['uniacid'],'fromuser'=>intval($_RQ['mid']));
	}
	if($_RQ['id']){
		$mid=$this->pdo_getcolumn('member',array('id'=>$_RQ['id']),'mid');
		$params=array('uniacid'=>$_SESSION['uniacid'],'fromuser'=>$mid);
	}
	$return['params']['mid']=$params['fromuser'];
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'createtime desc',
	);
	$list=$this->get_list('member',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['level_id']=$item['level_id'];
			$item['teamstatus']=$item['teamstatus'];
			$item['order_num']=$item['order_num'];
			$item['order_price']=$item['order_price'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export2',
		'list'=>array('data'=>'list','key'=>'mid','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'level_id','title'=>'团队长等级','type'=>'select','options'=>'levels'),
		),'action'=>array(
			array('type'=>'href','op'=>'member','title'=>'他的下线'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择上级'),
			array('name'=>'createtime','width'=>15,'title'=>'加入时间','type'=>'time_range'),
		),
	);
	$return['htmls']=$htmls;
	$return['agent_status']=$this->agent_status;
	$return['levels']=$this->getall('level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['levels']['0']=array('id'=>'0','title'=>'默认等级');
	exi($return);
}